import My from './view/My.vue'
import Loginin from './view/Loginin.vue'
import Register from './view/Register.vue'
import Forget from './view/Forget.vue'
import qpe from './view/qpe'
import FloatingWindow from './view/FloatingWindow'
import TimePicker from './view/TimePicker'
import TimePickerYu from './view/TimePickerYu'
import TimePickerRa from './view/TimePickerRa'
import TimePickerCo from './view/TimePickerCo'
import TimePickerSt from './view/TimePickerSt'
import TimePickerQpe from './view/TimePickerQpe'
import TimePickerRain from './view/TimePickerRain'
import TimePickerPre from './view/TimePickerPre'
import test from './view/test'
import Sidebar from './view/Sidebar'
import Rainfall from './view/Rainfall'
import Radar from './view/Radar'
import radarPic from './view/radarPic'
import convectivegust from './view/convectivegust'
import strongrain from './view/strongrain'
import Rectangle from './view/Rectangle'
import yuntu from './view/yuntu'
import Recognition from './view/Recognition'
import { createRouter, createWebHashHistory } from 'vue-router';
import store from "@/store";


const routes = [
  {
    path: '/my',
    name: 'my',
    component: My
  },
  {
    path: '/',
    name: 'login',
    component: Loginin,
  },
  {
    path:'/register',
    name:'register',
    component:Register
  },
  {
    path:'/forget',
    name:'forget',
    component:Forget
  },
  {
    path:'/qpe',
    name:'qpe',
    component: qpe
  },
  {
    path:'/FloatingWindow',
    name:'FloatingWindow',
    component: FloatingWindow
  },
  {
    path:'/TimePicker',
    name:'TimePicker',
    component: TimePicker
  },
  {
    path:'/test',
    name:'test',
    component: test
  },
  {
    path:'/Sidebar',
    name:'Sidebar',
    component: Sidebar
  },
  {
    path:'/Rainfall',
    name:'Rainfall',
    component: Rainfall
  },
  {
    path:'/Radar',
    name:'Radar',
    component: Radar
  },
  {
    path:'/Rectangle',
    name:'Rectangle',
    component: Rectangle
  },
  {
    path:'/yuntu',
    name:'yuntu',
    component: yuntu
  },
  {
    path:'/TimePickerYu',
    name:'TimePickerYu',
    component: TimePickerYu
  },
  {
    path:'/TimePickerRa',
    name:'TimePickerRa',
    component: TimePickerRa
  },
  {
    path:'/radarPic',
    name:'radarPic',
    component: radarPic
  },
  {
    path:'/TimePickerCo',
    name:'TimePickerCo',
    component: TimePickerCo
  },
  {
    path:'/convectivegust',
    name:'convectivegust',
    component: convectivegust
  },
  {
    path:'/TimePickerSt',
    name:'TimePickerSt',
    component: TimePickerSt
  },
  {
    path:'/strongrain',
    name:'strongrain',
    component: strongrain
  },
  {
    path:'/TimePickerQpe',
    name:'TimePickerQpe',
    component: TimePickerQpe
  },
  {
    path:'/Recognition',
    name:'Recognition',
    component: Recognition
  },
  {
    path:'/TimePickerRain',
    name:'TimePickerRain',
    component: TimePickerRain
  },
  {
    path:'/TimePickerPre',
    name:'TimePickerPre',
    component: TimePickerPre
  },
  {
    path: '/yuntu',
    component: yuntu,
    meta: { showFloatingWindow: true } // 标记需要显示悬浮窗
  },
  {
    path: '/Rainfall',
    component: Rainfall,
    meta: { showFloatingWindow: true } // 标记需要显示悬浮窗
  },
]

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes
});

const whiteList = ['login','register','forget','qpe','FloatingWindow','TimePicker','test','Sidebar','Rainfall','Radar','Rectangle','yuntu','TimePickerYu','TimePickerRa','radarPic','TimePickerCo','convectivegust','TimePickerSt','strongrain','TimePickerQpe','Recognition','TimePickerRain','TimePickerPre']

router.beforeEach((to,from,next)=>{
  let isLogin = store.state.isLogin
  //  如果用户匿名状态下访问非白名单页面，跳转到登录页面
  if(!whiteList.includes(to.name) && !isLogin){
    next({ path: '/' })
  }else{
    next()
  }
})


export default router
